﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;

namespace MidSoft.ProjectInfo
{
    public partial class ProjectCareModify : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int ProjectInfoId = (Convert.ToInt32(Request.Params["id"]));
                    ShowInfo(ProjectInfoId);
                    //ShowInfoPower(ProjectInfoId, ChinaSoft.Common.Input.SetInt(Session["currentUserID"]));
                }
            }
        }

        //private void ShowInfoPower(int ProjectInfoId, int userid)
        //{
        //    ChinaSoft.Model.Model_tb_MidSoft_CareProject modelCareProject = new ChinaSoft.Model.Model_tb_MidSoft_CareProject();
        //    ChinaSoft.BLL.BLL_tb_MidSoft_CareProject bllCareProject = new ChinaSoft.BLL.BLL_tb_MidSoft_CareProject();
        //    DataSet ds = bllCareProject.GetList("ProjectInfoId=" + ProjectInfoId + " and CreateUserId=" + userid);
        //    if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
        //    {
        //        this.ddlDepartMent.Enabled = false;
        //        this.txtProjectNum.Enabled = false;
        //        this.lblProjectName.Enabled = false;
        //        this.ddlProjectSpecialty.Enabled = false;
        //        this.ddlMarker.Enabled = false;
        //        this.txtArea.Enabled = false;
        //        this.txtCustomer.Enabled = false;
        //        this.ddlProperty.Enabled = false;
        //        this.ddlState.Enabled = false;
        //    }
        //}

        private void ShowInfo(int ProjectInfoId)
        {
            ChinaSoft.BLL.BLL_tb_MidSoft_ProjectInfo bll = new ChinaSoft.BLL.BLL_tb_MidSoft_ProjectInfo();
            ChinaSoft.Model.Model_tb_MidSoft_ProjectInfo model = bll.GetModel(ProjectInfoId);
            //MessageBox.Show(this,model.DepartMent.ToString());
            this.lblDepartMent.Text = model.DepartMent;
            this.lblProjectNum.Text = model.ProjectNumber;
            this.lblProjectName.Text = model.ProjectName;
            this.lblProjectSpecialty.Text = model.ProjectSpecialty;
            this.lblMarker.Text = model.Marker;
            //this.ddlMarker.SelectedIndex = this.ddlMarker.Items.IndexOf(ddlMarker.Items.FindByText(model.Marker));
            this.lblArea.Text = model.Area;
            this.lblCustomer.Text = model.Customer;
            this.lblProperty.Text = model.Property;

            this.lblContent.Text = model.Description;
            this.lblState.Text = model.ProjectState.ToString();
        }

        protected void ddlDepartMent_SelectedIndexChanged(object sender, EventArgs e)
        {
            SetProjectNumber();
        }
        /// <summary>
        /// 设置项目编号
        /// </summary>
        private void SetProjectNumber()
        {
            string strZy = "";

            strZy = "0" + GetProjectSpecialtyNumber(lblProjectSpecialty.Text);

            string strBh = System.DateTime.Now.Year + strZy + lblDepartMent.Text;
            this.lblProjectNum.Text = strBh.ToString();
        }
        private string GetProjectSpecialtyNumber(string projectspecialty)
        {
            string result = string.Empty;
            switch (projectspecialty)
            {
                case "公路":
                    result = "1";
                    break;
                case "水运":
                    result = "2";
                    break;
                case "市政":
                    result = "3";
                    break;
                case "轨道":
                    result = "4";
                    break;
                case "建筑":
                    result = "5";
                    break;
                case "试验":
                    result = "6";
                    break;
                case "科研":
                    result = "7";
                    break;
                case "其他":
                    result = "8";
                    break;
            }
            return result;
        }
        protected void ddlProjectSpecialty_SelectedIndexChanged(object sender, EventArgs e)
        {
            SetProjectNumber();
        }
    }
}